package com.jinyou.chengfengshop.utils;

import android.content.Context;
import android.content.SharedPreferences;




/**
 * Created by qingq on 2016/8/10.
 */
public class SharePreferenceUtils {

    private SharedPreferences sharedPreferences = null;

    private SharedPreferences.Editor editor = null;

    /**
     * 构造方法
     *
     * @param context
     */
    public SharePreferenceUtils(Context context) {
        if (context != null) {
            sharedPreferences = context.getSharedPreferences(
                    SystemConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
            editor = sharedPreferences.edit();
        }
    }

    /**
     * @param key
     * @param value
     */
    public void putBoolean(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.commit();
    }

    /**
     * @param key
     * @param value
     */
    public void putString(String key, String value) {
        editor.putString(key, value);
        editor.commit();
    }

    /**
     * @param key
     * @param defValue
     * @return
     */
    public String getString(String key, String defValue) {
        return sharedPreferences.getString(key, defValue);
    }


    /**
     * @param key
     * @param value
     */
    public void putInt(String key, int value) {
        editor.putInt(key, value);
        editor.commit();
    }

    /**
     * @param key
     * @param defValue
     * @return
     */
    public int getInt(String key, int defValue) {
        return sharedPreferences.getInt(key, defValue);
    }

    /**
     * @param key
     */
    public boolean getBoolean(String key) {
        return sharedPreferences.getBoolean(key, false);
    }


}
